// Copyright (c) 2002 HTHK
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1054: By Oscar Bai  Date:2003/02
//******************************************************************/
/*--------------------------------------------------------------
 * CRLOG	: CR1528
 * Fix		: User Profile Modificaitons 
 *			: - Add Company Code / Add Method to set/get UserMultiRole
 * By		: PH, HPMS
 * Date		: 02-Dec-2005
 *--------------------------------------------------------------
 */

package admin.system.user;

import java.util.Vector;

import com.ffpc.sql.*;

import admin.system.user.UserBean;

/**
 * A Class class.
 * <P>
 * @author HTHK
 */
public class User
  extends DataObject
  implements UserBean
{
    private String user_id = null;
    private String user_name = null;
    private String user_des = null;
    private transient String passwd = null; //not serialized for security reason
    private String pass_exp_date = null;
    private String role_id = null;
    private String cost_center_id = null;
    private String email = null;
    private String mobile = null;
    private String staff_id = null;
    private String active = null;
    private String crt_user = null;
    private String crt_date = null;
    private String upd_user = null;
    private String upd_date = null;

 //CR log no 1054 begin of: Define string

    private String inactive_date= null;
    private String deactivated_by=null;
    private String deactivated_date=null;

 //CR log no 1054 end of;

  
  // CR Log #: 1055   DATE: Jun 2003   BY: MLin
  
  // CR Description: To enable multi-company and JIS migration for SRS
    
    private String request_group = null;
  
//End of CRLog 1055
/* CR1528 */
	private String company_code	= null;
	private String login_trial	= null;

	// roles is not a field in jis_s_user
	private Vector roles		= null;
/* CR1528 */
	
	private boolean authenticated;

    private Column ColUser_id = null;
    private Column ColUser_name = null;
    private Column ColUser_des = null;
    private Column ColPasswd = null;
    private Column ColPass_exp_date = null;
    private Column ColRole_id = null;
    private Column ColCost_center_id = null;
    private Column ColEmail = null;
    private Column ColMobile = null;
    private Column ColStaff_id = null;
    private Column ColActive = null;
    private Column ColCrt_user = null;
    private Column ColCrt_date = null;
    private Column ColUpd_user = null;
    private Column ColUpd_date = null;

 //CR log no 1054 begin of: add new column for user class

    private Column ColInactive_date=null;
    private Column ColDeactivated_by=null;
    private Column ColDeactivated_date=null;

 //CR log no 1054 end of
// CR Log #: 1055   DATE: Jun 2003   BY: MLin
  
// CR Description: To enable multi-company and JIS migration for SRS
    
    private Column ColRequest_group = null;
  
//End of CRLog 1055
/* CR1528 */
	private Column ColCompany_code	= null;
	private Column ColLogin_trial	= null;
/* CR1528 */


    /**
     * Constructor
     */
    public User()
    {
        ColUser_id = new Column(0,"user_id",Column.Types.string,null,10,false);
        ColUser_name = new Column(1,"user_name",Column.Types.string,null,50,false);
        ColUser_des = new Column(2,"user_des",Column.Types.string,null,100,true);
        ColPasswd = new Column(3,"passwd",Column.Types.string,null,256,false);
        ColPass_exp_date = new Column(4,"pass_exp_date",Column.Types.time,null,10,true);
        ColRole_id = new Column(5,"role_id",Column.Types.string,null,10,false);
        ColCost_center_id = new Column(6,"cost_center_id",Column.Types.string,null,4,false);
        ColEmail = new Column(7,"email",Column.Types.string,null,50,true);
        ColMobile = new Column(8,"mobile",Column.Types.string,null,30,true);
        ColStaff_id = new Column(9,"staff_id",Column.Types.string,null,15,false);
        ColActive = new Column(10,"active",Column.Types.string,null,1,true);
        ColCrt_user = new Column(11,"crt_user",Column.Types.string,null,10,false);
        ColCrt_date = new Column(12,"crt_date",Column.Types.time,null,10,true);
        ColUpd_user = new Column(13,"upd_user",Column.Types.string,null,10,false);
        ColUpd_date = new Column(14,"upd_date",Column.Types.time,null,10,true);
        
 //CR log no 1054 begin of: add new column for user class

        ColInactive_date=new Column(15,"inactive_date",Column.Types.time,null,10,true);
        ColDeactivated_by=new Column(16,"deactivated_by",Column.Types.string,null,10,true);
        ColDeactivated_date=new Column(17,"deactivated_date",Column.Types.time,null,10,true);
 //CR log no 1054 end of

   
// CR Log #: 1055   DATE: Jun 2003   BY: MLin
   
// CR Description: To enable multi-company and JIS migration for SRS
        
        ColRequest_group = new Column(18,"request_group",Column.Types.string,null,10,true);
   
//End of CRLog 1055

/* CR1528 */
		ColCompany_code	= new Column(19, "company_code", Column.Types.string, null, 2, false);
		ColLogin_trial	= new Column(20, "login_trial", Column.Types.integer, null, 1, false);
/* CR1528 */

    }

    // functions belongs to UserBean interface

    @Override
	public void setUser_id(String user_id)
    {
        this.user_id = this.setAttribute(ColUser_id,user_id);
    }

    @Override
	public String getUser_id()
    {
        return this.user_id==null?"":this.user_id;
    }

    @Override
	public void setUser_name(String user_name)
    {
        this.user_name = this.setAttribute(ColUser_name,user_name);
    }

    @Override
	public String getUser_name()
    {
        return this.user_name==null?"":this.user_name;
    }

    @Override
	public void setUser_des(String user_des)
    {
        this.user_des = this.setAttribute(ColUser_des,user_des);
    }

    @Override
	public String getUser_des()
    {
        return this.user_des==null?"":this.user_des;
    }

    @Override
	public void setPasswd(String passwd)
    {
    //CR log no:no begin of: removed the JisEncrypt,Encrypt pass word in UserServlet.java 
    /* 
      //CR log no 1054 begin of:Encrypt password, JisEncrypt is new class 
 //        JisEncrypt jis_encrypt = new JisEncrypt();
 //       String tmpstr = jis_encrypt.Encrypt(passwd);
        //CR log no 1054 end of
 //        this.passwd = this.setAttribute(ColPasswd,tmpstr);
 */
        this.passwd = this.setAttribute(ColPasswd,passwd);
     //CR log no:no end of:
    }

    @Override
	public String getPasswd()
    {
        return this.passwd==null?"":this.passwd;
    }

    @Override
	public void setPass_exp_date(String pass_exp_date)
    {
        this.pass_exp_date = this.setAttribute(ColPass_exp_date,pass_exp_date);
    }

    @Override
	public String getPass_exp_date()
    {
        return this.pass_exp_date==null?"":this.pass_exp_date;
    }

    @Override
	public void setRole_id(String role_id)
    {
        this.role_id = this.setAttribute(ColRole_id,role_id);
    }

    @Override
	public String getRole_id()
    {
        return this.role_id==null?"":this.role_id;
    }

    @Override
	public void setCost_center_id(String cost_center_id)
    {
        this.cost_center_id = this.setAttribute(ColCost_center_id,cost_center_id);
    }

    @Override
	public String getCost_center_id()
    {
        return this.cost_center_id==null?"":this.cost_center_id;
    }

    @Override
	public void setEmail(String email)
    {
        this.email = this.setAttribute(ColEmail,email);
    }

    @Override
	public String getEmail()
    {
        return this.email==null?"":this.email;
    }

    @Override
	public void setMobile(String mobile)
    {
        this.mobile = this.setAttribute(ColMobile,mobile);
    }

    @Override
	public String getMobile()
    {
        return this.mobile==null?"":this.mobile;
    }

    @Override
	public void setStaff_id(String staff_id)
    {
        this.staff_id = this.setAttribute(ColStaff_id,staff_id);
    }

    @Override
	public String getStaff_id()
    {
        return this.staff_id==null?"":this.staff_id;
    }

    @Override
	public void setActive(String active)
    {
        this.active = this.setAttribute(ColActive,active);
    }

    @Override
	public String getActive()
    {
        return this.active==null?"":this.active;
    }

    @Override
	public void setCrt_user(String crt_user)
    {
        this.crt_user = this.setAttribute(ColCrt_user,crt_user);
    }

    @Override
	public String getCrt_user()
    {
        return this.crt_user==null?"":this.crt_user;
    }

    @Override
	public void setCrt_date(String crt_date)
    {
        this.crt_date = this.setAttribute(ColCrt_date,crt_date);
    }

    @Override
	public String getCrt_date()
    {
        return this.crt_date==null?"":this.crt_date;
    }

    @Override
	public void setUpd_user(String upd_user)
    {
        this.upd_user = this.setAttribute(ColUpd_user,upd_user);
    }

    @Override
	public String getUpd_user()
    {
        return this.upd_user==null?"":this.upd_user;
    }

    @Override
	public void setUpd_date(String upd_date)
    {
        this.upd_date = this.setAttribute(ColUpd_date,upd_date);
    }

    @Override
	public String getUpd_date()
    {
        return this.upd_date==null?"":this.upd_date;
    }
    
    //CR log no 1054 begin of: Add set and get Fuction for new Field

    @Override
	public void setInactive_date(String inactive_date)
    {
      this.inactive_date=this.setAttribute(ColInactive_date,inactive_date);
      }
    
    @Override
	public String getInactive_date()
    {
      return this.inactive_date==null?"":this.inactive_date;  
    }

    @Override
	public void setDeactivated_by(String deactivated_by)
    {
      this.deactivated_by=this.setAttribute(ColDeactivated_by,deactivated_by);
    }
    
    @Override
	public String getDeactivated_by()
    {
      return this.deactivated_by==null?"":this.deactivated_by;   
    }

    @Override
	public void setDeactivated_date(String deactivated_date)
    {
      this.deactivated_date=this.setAttribute(ColDeactivated_date,deactivated_date);
    }

    @Override
	public String getDeactivated_date()
    {
      return this.deactivated_date==null?"":this.deactivated_date;
    }

    //CR log no 1054 end of
    // CR Log #: 1055   DATE: Jun 2003   BY: MLin
    
    // CR Description: To enable multi-company and JIS migration for SRS
    @Override
	public void setRequest_group(String request_group)

    {
      this.request_group=this.setAttribute(ColRequest_group,request_group);
    }

    @Override
	public String getRequest_group()
    {
      return this.request_group==null?"":this.request_group;
    }
    //End of CRLog 1055

/* CR1528 */
    @Override
	public void setCompany_code(String cc)
    {
      this.company_code=this.setAttribute(ColCompany_code,cc);
    }

	@Override
	public String getCompany_code()
	{
		return this.company_code==null?"":this.company_code;
	}

	@Override
	public void setLogin_trial(String lt)
	{
	  this.login_trial=this.setAttribute(ColLogin_trial, lt);
	}

	@Override
	public String getLogin_trial()
	{
		return this.login_trial==null?"0":this.login_trial;
	}

	//this.roles is not field in jis_s_user
	@Override
	public void setRoles( Vector multirole ) 
	{
		this.roles=multirole;
	}

	@Override
	public Vector getRoles() 
	{
		return this.roles;
	}

	@Override
	public boolean isRole( String role ) 
	{
		return this.roles.contains( role );
	}
/* CR1528 */

    // belongs to row interface
    @Override
	public Column[] createColumns()
    {
        Column[] cols = new Column[21];
        cols[0] = ColUser_id.clone(null);
        cols[1] = ColUser_name.clone(null);
        cols[2] = ColUser_des.clone(null);
        cols[3] = ColPasswd.clone(null);
        cols[4] = ColPass_exp_date.clone(null);
        cols[5] = ColRole_id.clone(null);
        cols[6] = ColCost_center_id.clone(null);
        cols[7] = ColEmail.clone(null);
        cols[8] = ColMobile.clone(null);
        cols[9] = ColStaff_id.clone(null);
        cols[10] = ColActive.clone(null);
        cols[11] = ColCrt_user.clone(null);
        cols[12] = ColCrt_date.clone(null);
        cols[13] = ColUpd_user.clone(null);
        cols[14] = ColUpd_date.clone(null);

//CR log no 1054 begin of:Add  New Cols and Change the Cols num

        cols[15] = ColInactive_date.clone(null);
        cols[16] = ColDeactivated_by.clone(null);
        cols[17] = ColDeactivated_date.clone(null);

//CR log no 1054 end of
// CR Log #: 1055   DATE: Jun 2003   BY: MLin
    
// CR Description: To enable multi-company and JIS migration for SRS
        
        cols[18] = ColRequest_group.clone(null);
    
// End of CRLog 1055

/* CR1528 */
		cols[19] = ColCompany_code.clone(null);
		cols[20] = ColLogin_trial.clone(null);
/* CR1528 */

        return cols;
    }

    // super's abstract methods

    @Override
	public String getTableName()
    {
        return "jis.jis_s_user";
    }

    @Override
	protected String[] getKeyColumnNames()
    {
        String[] list = {"user_id"};
        return list;
    }

    @Override
	protected String[] getUpdatableColumnNames()
    {

    //CR log no 1054 begin of: Add new field to List
// CR Log #: 1055   DATE: Jun 2003   BY: MLin
    
// CR Description: To enable multi-company and JIS migration for SRS
    
// Add new field to List


/* CR1528 - add company_code */
	String[] list = {
					"user_name"
					,"user_des"
					,"passwd"
					,"pass_exp_date"
					,"role_id"
					,"cost_center_id"
					,"email"
					,"mobile"
					,"staff_id"
					,"active"
					,"crt_user"
					,"crt_date"
					,"upd_user"
					,"upd_date"
					,"inactive_date"
					,"deactivated_by"
					,"deactivated_date"
					,"request_group"
					,"company_code"
					,"login_trial"
					};

    //CR log no 1054 end of
/* CR1528 */
        return list;
    }

    @Override
	protected void retrieveColumnValues()
    {
        this.user_id = this.retrieveColumnValue("user_id");
        this.user_name = this.retrieveColumnValue("user_name");
        this.user_des = this.retrieveColumnValue("user_des");
        this.passwd = this.retrieveColumnValue("passwd");
        this.pass_exp_date = this.retrieveColumnValue("pass_exp_date");
        this.role_id = this.retrieveColumnValue("role_id");
        this.cost_center_id = this.retrieveColumnValue("cost_center_id");
        this.email = this.retrieveColumnValue("email");
        this.mobile = this.retrieveColumnValue("mobile");
        this.staff_id = this.retrieveColumnValue("staff_id");
        this.active = this.retrieveColumnValue("active");
        this.crt_user = this.retrieveColumnValue("crt_user");
        this.crt_date = this.retrieveColumnValue("crt_date");
        this.upd_user = this.retrieveColumnValue("upd_user");
        this.upd_date = this.retrieveColumnValue("upd_date");

    //CR log no 1054 begin of:Add new Column's Value

        this.inactive_date=this.retrieveColumnValue("inactive_date");
        this.deactivated_by=this.retrieveColumnValue("deactivated_by");
        this.deactivated_date=this.retrieveColumnValue("deactivated_date");

//CR log no 1054 end of

    
// CR Log #: 1055   DATE: Jun 2003   BY: MLin
    
// CR Description: To enable multi-company and JIS migration for SRS
        
        this.request_group=this.retrieveColumnValue("request_group");
    
// End of CRLog 1055

	/* CR1528 */
		this.company_code = this.retrieveColumnValue("company_code");
		this.login_trial  = this.retrieveColumnValue("login_trial");
	/* CR1528 */
    }

    @Override
    public boolean isAuthenticated() {
        return authenticated;
    }

    @Override
    public void setAuthenticated(boolean authenticated) {
        this.authenticated = authenticated;
    }
}

